package com.wz.project.rgvqueue.controller;


import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.rgvqueue.domain.RgvDeviceExecutionQueue;
import com.wz.project.rgvqueue.service.IRgvDeviceExecutionQueueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * RGV执行队列Controller
 * 
 * @author wld
 * @date 2023-04-06
 */
@Controller
@RequestMapping("/device/rgvqueue")
public class RgvDeviceExecutionQueueController extends BaseController
{
    private String prefix = "device/rgvqueue";

    @Autowired
    private IRgvDeviceExecutionQueueService rgvDeviceExecutionQueueService;

    @RequiresPermissions("device:rgvqueue:view")
    @GetMapping()
    public String rgvqueue()
    {
        return prefix + "/rgvqueue";
    }

    /**
     * 查询RGV执行队列列表
     */
//    @RequiresPermissions("device:rgvqueue:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RgvDeviceExecutionQueue rgvDeviceExecutionQueue)
    {
        startPage();
        List<RgvDeviceExecutionQueue> list = rgvDeviceExecutionQueueService.selectRgvDeviceExecutionQueueList(rgvDeviceExecutionQueue);
        return getDataTable(list);
    }

    /**
     * 导出RGV执行队列列表
     */
    @Log(title = "RGV执行队列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RgvDeviceExecutionQueue rgvDeviceExecutionQueue)
    {
        List<RgvDeviceExecutionQueue> list = rgvDeviceExecutionQueueService.selectRgvDeviceExecutionQueueList(rgvDeviceExecutionQueue);
        ExcelUtil<RgvDeviceExecutionQueue> util = new ExcelUtil<RgvDeviceExecutionQueue>(RgvDeviceExecutionQueue.class);
        return util.exportExcel(list, "RGV执行队列数据");
    }


    /**
     * 重新下发堆垛机执行队列
     */
    @Log(title = "RGV执行队列", businessType = BusinessType.UPDATE)
    @RequestMapping("/reloadTask")
    @ResponseBody
    public AjaxResult reloadTask(RgvDeviceExecutionQueue queue){
        int sa = rgvDeviceExecutionQueueService.reloadTask(queue);
        if(sa == 1){
            return AjaxResult.success("重新下发成功！");
        }else{
            return AjaxResult.error("只有正执行的队列才可以重新下发！");
        }
    }

    /**
     * 删除堆垛机执行队列
     */
    @Log(title = "RGV执行队列", businessType = BusinessType.DELETE)
    @RequestMapping("/deleteTask")
    @ResponseBody
    public AjaxResult deleteTask(RgvDeviceExecutionQueue queue){
        int sa = rgvDeviceExecutionQueueService.deleteTask(queue);
        if(sa == 1){
            return AjaxResult.success("删除成功！");
        }else{
            return AjaxResult.error("只有正执行的队列才可以删除！");
        }
    }
}
